package com.qcby.controller;

import com.qcby.common.Result;
import com.qcby.form.TLifeInfoForm;
import com.qcby.form.TLifeInfoListForm;
import com.qcby.service.TLifeInfoService;
import com.qcby.vo.PageVO;
import com.qcby.vo.TLifeInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 生活资讯 前端控制器
 * </p>
 *
 * @author admin
 * @since 2025-02-04
 */
@RestController
@RequestMapping("/life-info")
public class TLifeInfoController {

    @Autowired
    private TLifeInfoService lifeInfoService;

    /**
     * 资讯列表
     */
    @GetMapping("/list")
    public Result<PageVO<TLifeInfoVO>> list(@Valid TLifeInfoListForm form) {
        PageVO<TLifeInfoVO> pageVO = lifeInfoService.getLifeInfoList(form);
        return Result.success(pageVO);
    }

    /**
     * 资讯详情
     */
    @GetMapping("/{id}")
    public Result<TLifeInfoVO> detail(@PathVariable("id") Integer id) {
        TLifeInfoVO detail = lifeInfoService.getLifeInfoDetail(id);
        return Result.success(detail);
    }

    /**
     * 添加资讯
     */
    @PostMapping
    public Result add(@RequestBody @Valid TLifeInfoForm form) {
        lifeInfoService.addLifeInfo(form);
        return Result.success();
    }

    /**
     * 修改资讯
     */
    @PutMapping("/{id}")
    public Result update(@PathVariable("id") Integer id, @RequestBody @Valid TLifeInfoForm form) {
        lifeInfoService.updateLifeInfo(id, form);
        return Result.success();
    }

    /**
     * 删除资讯
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Integer id) {
        lifeInfoService.deleteLifeInfo(id);
        return Result.success();
    }

    /**
     * 推送资讯
     */
    @PostMapping("/{id}/push")
    public Result push(@PathVariable("id") Integer id) {
        lifeInfoService.pushLifeInfo(id);
        return Result.success();
    }
}

